package com.smart.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.core.domain.AjaxResult;
import com.smart.common.enums.BusinessType;
import com.smart.manage.domain.DrugMovements;
import com.smart.manage.service.IDrugMovementsService;
import com.smart.common.utils.poi.ExcelUtil;
import com.smart.common.core.page.TableDataInfo;

/**
 * 药品变动明细Controller
 * 
 * @author lingyao
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/manage/drugMovements")
public class DrugMovementsController extends BaseController
{
    @Autowired
    private IDrugMovementsService drugMovementsService;

    /**
     * 查询药品变动明细列表
     */
    @PreAuthorize("@ss.hasPermi('manage:drugMovements:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugMovements drugMovements)
    {
        startPage();
        List<DrugMovements> list = drugMovementsService.selectDrugMovementsList(drugMovements);
        return getDataTable(list);
    }

    /**
     * 导出药品变动明细列表
     */
    @PreAuthorize("@ss.hasPermi('manage:drugMovements:export')")
    @Log(title = "药品变动明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrugMovements drugMovements)
    {
        List<DrugMovements> list = drugMovementsService.selectDrugMovementsList(drugMovements);
        ExcelUtil<DrugMovements> util = new ExcelUtil<DrugMovements>(DrugMovements.class);
        util.exportExcel(response, list, "药品变动明细数据");
    }

    /**
     * 获取药品变动明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:drugMovements:query')")
    @GetMapping(value = "/{movementId}")
    public AjaxResult getInfo(@PathVariable("movementId") Long movementId)
    {
        return success(drugMovementsService.selectDrugMovementsByMovementId(movementId));
    }

    /**
     * 新增药品变动明细
     */
    @PreAuthorize("@ss.hasPermi('manage:drugMovements:add')")
    @Log(title = "药品变动明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugMovements drugMovements)
    {
        return toAjax(drugMovementsService.insertDrugMovements(drugMovements));
    }

    /**
     * 修改药品变动明细
     */
    @PreAuthorize("@ss.hasPermi('manage:drugMovements:edit')")
    @Log(title = "药品变动明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugMovements drugMovements)
    {
        return toAjax(drugMovementsService.updateDrugMovements(drugMovements));
    }

    /**
     * 删除药品变动明细
     */
    @PreAuthorize("@ss.hasPermi('manage:drugMovements:remove')")
    @Log(title = "药品变动明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{movementIds}")
    public AjaxResult remove(@PathVariable Long[] movementIds)
    {
        return toAjax(drugMovementsService.deleteDrugMovementsByMovementIds(movementIds));
    }
}
